package com.igroupes.ovineherd.raw.service.raw;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igroupes.ovineherd.dto.ModelOrder;
import com.igroupes.ovineherd.entity.DataModelAttributeEntity;
import com.igroupes.ovineherd.entity.DataModelTableEntity;
import com.igroupes.ovineherd.mapper.DataModelAttributeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DataModelAttributeService extends ServiceImpl<DataModelAttributeMapper, DataModelAttributeEntity> {

    @Autowired
    private DataModelAttributeMapper dataModelAttributeMapper;

    public List<DataModelAttributeEntity> filedJsonAll(Integer tableId) {
        QueryWrapper<DataModelAttributeEntity> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(DataModelAttributeEntity::getTableId, tableId);
        return dataModelAttributeMapper.selectList(wrapper);
    }


    public DataModelTableEntity getByFieldId(Long fieldId) {
        return dataModelAttributeMapper.getByFieldId(fieldId);
    }
    public void deleteAttribute(Long userId, Long versionId){
        Map<String, Long> map = new HashMap<>();
        map.put("userId",userId);
        map.put("versionId", versionId);
        this.getBaseMapper().deleteAttribute(map);
    }

    public int order(List<ModelOrder> attributeModelOrder, Long versionId, Long userId) {
        Map map = new HashMap();
        map.put("orders", attributeModelOrder);
        map.put("versionId", versionId);
        map.put("userId", userId);
        return this.getBaseMapper().order(map);
    }
}
